package com.enjoy.service.impl;

import com.enjoy.domain.Permissions;
import com.enjoy.domain.Role;
import com.enjoy.domain.VdsUser;
import com.enjoy.mapper.LoginMapper;
import com.enjoy.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 姜风
 * @date 2021/9/7 9:55
 */
@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;

    /**
     * 根据用户名获取用户信息
     *
     * @param username 用户名
     * @return 用户
     */
    @Override
    public VdsUser getUserByName(String username) {
        VdsUser user = loginMapper.getUserByName(username);
        Permissions permissions = new Permissions(1, "all");
        List<Permissions> permissionsList = new ArrayList<>();
        permissionsList.add(permissions);
        Role role = new Role(1, "admin", permissionsList);
        List<Role> roleList = new ArrayList<>();
        roleList.add(role);
        if (user == null) {
            return null;
        }
        user.setRoles(roleList);
        return user;
    }
}
